home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * Logger.js
- *
- * USAGE
- * Part of Netobjects JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2005 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
-
- if (!IS_isModuleInitialized("IS.NOF.UTIL.LOGGING.Logger"))
- {
- /****h* NOF_JavaScript_Library/NOF.UTIL.LOGGING.Logger
- *
- * NAME
- * NOF.UTIL.LOGGING.Logger
- *
- * DESCRIPTION
- *
- * The <code>Logger</code> class provides the methods to trace (and notify the
- * LOGGING system of) the events occured in an application module,
- * like info, warning, severe or log.
- * It offers the possibility to manage a list of handlers (predefined,
- * like <code>Handler</code>, <code>ConsoleHandler</code> or user defined ones).
- * Each handler in the list will receive a log record (as parameter of <code>Handler.publish</code> method)
- * It can have also a resource bundle from which the LOGGING mechanism would extract localized messages.
- *
- ****/
-
- /**
- * constructor (should not be called from outside the LOGGING module).
- * @param id - Logger identification string
- * @param bundle - localized resource
- **/
- function LOGGING_Logger( /*string*/ id, bundle ) {
- this.__proto__ = LOGGING_Logger.prototype;
-
- this.ID = id;
- this.resourceBundle = bundle;
-
- this.level = 0;
- this.handlers = new Array();
- }
- {
- var member = LOGGING_Logger.prototype;
- member.CLASS_NAME = "LOGGING.Logger";
-
- var method = LOGGING_Logger.prototype;
- /**
- * Get this Logger id.
- **/
- method.getLoggerName = function () { return this.ID; }
-
- /**
- * Set the minumum level from which the records passed through this Logger should be processed
- * @param level one of the values defined by LOGGING.Level interface
- **/
- method.setLevel = function (/*int*/ level) { this.level = level; }
- /**
- * Get the minimum log level from which the records passed through this Logger will be processed.
- * @return level associated with this record.
- **/
- method.getLevel = function () { return this.level;}
-
- /**
- * Determine if a record with a given level will be processed by this Logger.
- *
- * @param level
- * @return true if the level parameter is less or equal than the Logger's level set.
- **/
- method.isLoggable = function (/*int*/ level) { return (this.level >= level); }
-
- /**
- * Append a new Handler at the list of the handlers of this Logger.
- *
- * @param hnd the handler instance
- **/
- method.addHandler = function (/*NOF.UTIL.LOGGING.Handler*/ hnd) {
- if (this.handlers.containsItem(hnd) < 0) {
- this.handlers[this.handlers.length] = hnd;
- }
- }
- /**
- * Remove a specified Handler from the handlers list of this Logger.
- *
- * @param hnd the handler instance
- **/
- method.removeHandler = function (/*NOF.UTIL.LOGGING.Handler*/ hnd) {
- this.handlers.removeItem(this.handlers.containsItem(hnd));
- }
- /**
- * Get the Logger's list of handlers
- *
- * @return the list (Array) of handlers of this Logger
- **/
- method.getHandlers = function () { return this.handlers; }
-
- /**
- * Logs a record, if loggable.
- * @param logRecord
- **/
- /* protected */ method.doLog = function (/*NOF.UTIL.LOGGING.LogRecord*/ logRecord) {
- if (this.isLoggable(logRecord.getLevel())) {
- for (var i=0; i < this.handlers.length; i++) {
- this.handlers[i].publish(logRecord);
- }
- }
- }
-
- /**
- * Convenience method to log important messages (of whose notification is critical).
- * Equivalent of calling: log(LOGGING.Level.SEVERE, sourceClass, sourceMethod, message, params);
- * @param message
- * @param sourceClass (optional)
- * @param sourceMethod (optional)
- * @param params parameters used for formatting the message (optional)
- **/
- method.severe = function (message, sourceClass, sourceMethod, params) {
- this.log(LOGGING.Level.SEVERE, sourceClass, sourceMethod, message, params);
- }
-
- /**
- * Convenience method to log warning messages (of whose notification is important).
- * Equivalent of calling: log(LOGGING.Level.WARNING, sourceClass, sourceMethod, message, params);
- * @param message
- * @param sourceClass (optional)
- * @param sourceMethod (optional)
- * @param params parameters used for formatting the message (optional)
- **/
- method.warning = function (message, sourceClass, sourceMethod, params) {
- this.log(LOGGING.Level.WARNING, sourceClass, sourceMethod, message, params);
- }
-
- /**
- * Convenience method to log state information or to trace the activity of the module.
- * (to be used for medium level importance messages)
- * Equivalent of calling: log(LOGGING.Level.INFO, sourceClass, sourceMethod, message, params);
- * @param message
- * @param sourceClass (optional)
- * @param sourceMethod (optional)
- * @param params parameters used for formatting the message (optional)
- **/
- method.info = function (message, sourceClass, sourceMethod, params) {
- this.log(LOGGING.Level.INFO, sourceClass, sourceMethod, message, params);
- }
-
- /**
- * The method to be used if no other convenience method is provided for your needs.
- * Based on the parameters, it creates a LogRecord object which (if stated as qualified for LOGGING
- * by the isLoggable() method) will be passed to all the Handler objects of this Logger to be published.
- *
- * @param level
- * @param message
- * @param sourceClass (optional)
- * @param sourceMethod (optional)
- * @param params parameters used for formatting the message (optional)
- **/
- method.log = function (level, sourceClass, sourceMethod, msg, /*Object[]*/ params) {
- var lr = new LOGGING.LogRecord(level, msg);
- if (typeof(sourceClass) != "undefined") lr.setSourceClassName(sourceClass);
- if (typeof(sourceMethod) != "undefined") lr.setSourceMethodName(sourceMethod);
- if (typeof(params) != "undefined") lr.setParameters(params);
- lr.setResourceBundle(this.resourceBundle);
- this.doLog(lr);
- }
-
- /**
- * Set the localization resource bundle of this Logger.
- *
- * @param bundle localization bundle
- */
- method.setResourceBundle = function (bundle) { this.resourceBundle = bundle; }
- /**
- * Get the localization resource bundle of this Logger.
- *
- * @return localization bundle
- **/
- method.getResourceBundle = function () { return this.resourceBundle; }
-
- }
-
- LOGGING.__proto__.Logger = LOGGING_Logger;
- }